export default {
  mounted(el: HTMLElement, binding: any) {
    const { value } = binding
    // 延迟获取store实例，确保Pinia已初始化
    const { useUserStore } = require('@/store')
    const userStore = useUserStore()
    
    if (value && value instanceof Array && value.length > 0) {
      const requiredRoles = value
      const userRoles = userStore.userInfo?.roles || []
      
      const hasRole = userRoles.some((role: string) => {
        return requiredRoles.includes(role)
      })
      
      if (!hasRole) {
        el.style.display = 'none'
      }
    } else {
      throw new Error('权限指令需要至少一个角色参数，例如 v-permission="[\'admin\']"')
    }
  }
}